package myQuene;
//队列(线性)
public class MyQuene {
    int[] elem;

    MyQuene() {
        elem = new int[10];
    }

    int front;
    int rare;

    //入队
    public void offer(int val) {
        if (isFull()) {
            throw new RuntimeException("队列已满");
        }
        elem[rare] = val;
        rare = (rare + 1) % elem.length;
    }

    //出队
    public int poll() {
        if (isEmpty()) {
            throw new RuntimeException("队列为空");
        }
        int ret = elem[front];
        front = (front + 1) % elem.length;
        return ret;
    }

    //展示队头元素
    public int peek() {
        if (isEmpty()) {
            throw new RuntimeException("队列为空");
        }
        return elem[front];
    }

    //判断是否已满
    public boolean isFull() {
        return (rare + 1) % elem.length == front;
    }

    public boolean isEmpty() {
        return front == rare;
    }
}
